package com.ruoyi.web.controller.system;


import com.ruoyi.common.core.page.ResponseResult;
import com.ruoyi.system.domain.Goods;
import com.ruoyi.system.domain.ZfbConfig;
import com.ruoyi.system.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "管理后台:支付宝配置相关接口")
@RestController
@RequestMapping("/admin/goods")
public class AdminGoodsController extends AdminController {


    @Resource
    private GoodsService zfbConfigService;

    @ApiOperation(value = "支付宝参数列表")
    @GetMapping("list")
    public ResponseResult<List<ZfbConfig>> list(Goods zfbConfig) {
        this.checkAdmin();
        this.startPage();
        List<Goods> list = zfbConfigService.findList(zfbConfig);
        return this.setSuccessResult(this.getPageResult(list));
    }

    @ApiOperation(value = "启用/禁用")
    @PostMapping("updateStatus")
    public ResponseResult updateStatus(@RequestBody Goods zfbConfig) {
        this.checkAdmin();
        zfbConfigService.updateDomain(zfbConfig);
        return this.setSuccessResult();
    }

    @ApiOperation(value = "新增")
    @PostMapping("save")
    public ResponseResult save(@RequestBody Goods zfbConfig) {
        this.checkAdmin();
        if (zfbConfig.getId() != null) {
            zfbConfigService.updateDomain(zfbConfig);
        } else {
            zfbConfigService.addDomain(zfbConfig);
        }

        return this.setSuccessResult();
    }


    @ApiOperation(value = "详情")
    @GetMapping("getById")
    public ResponseResult get(Long id) {
        this.checkAdmin();
        Goods zfbConfig = zfbConfigService.getById(id);

        return this.setSuccessResult(zfbConfig);
    }

    @ApiOperation(value = "删除")
    @GetMapping("delById")
    public ResponseResult delById(Long id) {
        this.checkAdmin();
        zfbConfigService.delById(id);

        return this.setSuccessResult();
    }

}
